<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @cancel="handleCancel"
  >
    <template slot="footer">
      <div>
        <a-button @click="saveDraft" style="margin-right: 10px;">暂存</a-button>
        <a-button :loading="confirmLoading" type="primary" @click="handleOk">提交</a-button>
      </div>
    </template>
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form" :labelCol="{span:7}" :wrapperCol="{span:15}">
        <a-row>
          <h2>订单信息：</h2>
        </a-row>
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="订单号">
              <a-input
                v-decorator="['orderNumber', { rules: [{ required: true, message: '请输入订单号'}] }]"
                placeholder="请输入订单号"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="汽车报价金额">
              <a-input-number
                v-decorator="['quoteAmount', { rules: [{ required: true, message: '请输入汽车报价' }] }]"
                placeholder="请输入订单总价"
                style="width: 100%"
                :min="0"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="订/定金金额">
              <a-input-number
                v-decorator="['epositAmount', { rules: [{ required: true, message: '请输入订/定金金额' }] }]"
                placeholder="请输入订/定金金额"
                style="width: 100%"
                :min="0"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="订单生成时间">
              <a-date-picker
                v-decorator="['orderDate', {initialValue: currentTime, rules: [{ required: true, message: '请输入订单生成时间' }] }]"
                :showTime="true"
                format="YYYY-MM-DD HH:mm:ss"
                placeholder="请输入订单生成时间"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>


        </a-row>
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="订/定金性质">
              <a-select
                v-decorator="['depositAttribute', { rules: [{ required: true, message: '请选择订/定金性质' }] }]"
                placeholder="请选择订/定金性质"
                @change="changeDepositNotes"
              >

                <a-select-option value="1">可退</a-select-option>
                <a-select-option value="2">不可退</a-select-option>
                <a-select-option value="3">有条件可退</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col v-if="showDing" :sm="12" :xs="24">
            <a-form-item label="订/定金不可退原因">
              <a-textarea
                v-decorator="['depositNotes', { rules: [{ required: false, message: '请输入订/定金不可退原因' }] }]"
                placeholder="请输入订/定金不可退原因"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <h2>销售方信息：</h2>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="企业名称">
              <a-input
                v-decorator="['enterpriseName', { rules: [{ required: false, message: '请输入企业名称' }] }]"
                placeholder="请输入企业名称"
                style="width: 100%"
                read-only
              />
            </a-form-item>
          </a-col>

          <a-col :sm="12" :xs="24">
            <a-form-item label="社会信用统一代码">
<!--              <a-input-->
<!--                v-decorator="['enterpriseUscc', { rules: [{ required: true, message: '请输入社会信用统一代码' }] }]"-->
<!--                :disabled="showEnterpriseUscc"-->
<!--                placeholder="请输入社会信用统一代码"-->
<!--                style="width: 100%"-->
<!--              />-->
              <a-input
                v-decorator="['enterpriseUscc', { rules: [{ required: true, message: '请输入社会信用统一代码' }] }]"
                placeholder="请输入社会信用统一代码"
                style="width: 100%"
                read-only
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="销售区域">
              <a-input
                v-decorator="['region', { rules: [{ required: true, message: '请选择销售区域' }] }]"
                placeholder="请选择销售区域"
                style="width: 100%"
                read-only
              />
<!--              <a-select-->
<!--                v-decorator="['region', { rules: [{ required: true, message: '请选择销售区域' }] }]"-->
<!--                placeholder="请选择销售区域"-->
<!--              >-->

<!--                <a-select-option value="黄浦区">黄浦区</a-select-option>-->
<!--                <a-select-option value="徐汇区">徐汇区</a-select-option>-->
<!--                <a-select-option value="长宁区">长宁区</a-select-option>-->
<!--                <a-select-option value="静安区">静安区</a-select-option>-->
<!--                <a-select-option value="普陀区">普陀区</a-select-option>-->
<!--                <a-select-option value="虹口区">虹口区</a-select-option>-->
<!--                <a-select-option value="杨浦区">杨浦区</a-select-option>-->
<!--                <a-select-option value="闵行区">闵行区</a-select-option>-->
<!--                <a-select-option value="宝山区">宝山区</a-select-option>-->
<!--                <a-select-option value="嘉定区">嘉定区</a-select-option>-->
<!--                <a-select-option value="浦东新区">浦东新区</a-select-option>-->
<!--                <a-select-option value="金山区">金山区</a-select-option>-->
<!--                <a-select-option value="松江区">松江区</a-select-option>-->
<!--                <a-select-option value="青浦区">青浦区</a-select-option>-->
<!--                <a-select-option value="奉贤区">奉贤区</a-select-option>-->
<!--                <a-select-option value="崇明区">崇明区</a-select-option>-->
<!--                <a-select-option value="外省">外省</a-select-option>-->
<!--                <a-select-option value="线上平台">线上平台</a-select-option>-->
<!--                <a-select-option value="其他">其他</a-select-option>-->
<!--              </a-select>-->
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="销售地址">
              <a-input
                v-decorator="['businessAddress', { rules: [{ required: true, message: '请输销售地址' }] }]"
                placeholder="请输入销售地址"
                read-only
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="销售顾问姓名">
              <a-auto-complete
                v-decorator="['salesName', { rules: [{ required: false, message: '请输入销售顾问姓名' }] }]"
                :data-source="saleSource"
                placeholder="请输入销售顾问姓名"
                style="width: 100%"
                @change="saleChange"
                @select="saleSelect"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="销售顾问手机号码">
              <a-input
                v-decorator="['salesPhone', { rules: [{ required: false, message: '请核对手机号码格式',pattern: new RegExp(/(^1[3|4|5|8][0-9]\d{4,8}$)|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)/), }] }]"
                placeholder="请输入销售顾问手机号码"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <h2>订购方信息：</h2>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="订购方姓名">
              <a-input
                v-decorator="['ownerName', { rules: [{ required: true, message: '请输入订购方姓名' }] }]"
                placeholder="请输入订购方姓名"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="订购方的电话">
              <a-input
                v-decorator="['ownerPhone', { rules: [{ required: true, message: '请输入订购方的电话',pattern: new RegExp(/(^1[3|4|5|8][0-9]\d{4,8}$)|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)/), }] }]"
                placeholder="请输入订购方的电话"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="订购方证件类型">
              <a-select
                v-decorator="['documentType',{  initialValue:'1'}, { rules: [{ required: true, message: '请选择订购方证件类型' }],}]"
                placeholder="请选择订购方证件类型"
              >

                <a-select-option value="1">身份证</a-select-option>
                <a-select-option value="2">护照</a-select-option>
                <a-select-option value="3">士兵证军官证</a-select-option>
                <a-select-option value="4">港澳居民居住证</a-select-option>
                <a-select-option value="5">港澳居民来往内地通行证</a-select-option>
                <a-select-option value="6">台湾居民居住证</a-select-option>
                <a-select-option value="7">台湾居民来往大陆通行证</a-select-option>
                <a-select-option value="8">外国人永久居留身份证</a-select-option>
                <a-select-option value="9">其他有效身份证明</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :sm="12" :xs="24">
            <a-form-item label="订购方证件号码">
              <!--              <a-input-->
              <!--                v-if="model.documentType === 1"-->
              <!--                placeholder="请输入订购方证件号码"-->
              <!--                v-decorator="['documentNumber', { rules: [{ required: true, message: '请输入订购方证件号码' ,pattern: new RegExp(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/),}] }]"-->
              <!--              />-->
              <a-input
                v-decorator="['documentNumber', { rules: [{ required: true,message: '请输入订购方证件号码' }, {
            trigger: 'change',
            validator: this.IdentityVerify,
          }] }]"
                placeholder="请输入订购方证件号码"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <h2>车辆信息:</h2>
        </a-row>
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="汽车品牌">
              <a-input
                v-decorator="['carBrand', { rules: [{ required: true, message: '请输入汽车品牌' }] }]"
                placeholder="请输入汽车品牌"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="汽车车型">
              <a-input
                v-decorator="['carModel', { rules: [{ required: false, message: '请输入汽车车型' }] }]"
                placeholder="请输入汽车车型"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="车架号（VIN码）">
              <a-input
                v-decorator="['carVin', { rules: [{ required: false, message: '请输入车架号' }] }]"
                placeholder="请输入车架号"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="汽车类型">
              <a-select
                v-decorator="['carType', { rules: [{ required: true, message: '请输入汽车类型' }] }]"
                placeholder="请选择汽车类型"
                @change="changeCarType"
              >

                <a-select-option value="1">燃油车</a-select-option>
                <a-select-option value="2">新能源汽车</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="车型配置">
              <a-input
                v-decorator="['carTypeConfiguration', { rules: [{ required: true, message: '请输入车型配置' }] }]"
                placeholder="请输入车型配置"
              />
            </a-form-item>
          </a-col>

          <a-col :sm="12" :xs="24">
            <a-form-item label="汽车燃料类型">
              <a-select
                v-decorator="['fuelType', { rules: [{ required: false, message: '请输入汽车燃料类型' }] }]"
                placeholder="请选择汽车燃料类型"
              >
                <a-select-option value="1">油/电</a-select-option>
                <a-select-option value="2">电</a-select-option>
                <a-select-option value="3">油</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="是否为新车">
              <a-select
                v-decorator="['isNewCar', { rules: [{ required: true, message: '是否为新车' }], initialValue: '是' }]"
                placeholder="请选择是否为新车"
              >
                <a-select-option value="是">是</a-select-option>
                <a-select-option value="否">否</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="进口车辆随车检验单号">
              <a-input
                v-decorator="[
                  'importEngineNumber',
                  { rules: [{ required: false, message: '请输入进口机动车辆随车检验单号' }] },
                ]"
                placeholder="请输入进口机动车辆随车检验单号"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="外饰颜色">
              <a-input
                v-decorator="['carColor', { rules: [{ required: true, message: '请输入外饰颜色' }] }]"
                placeholder="请输入外饰颜色"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="内饰颜色">
              <a-input
                v-decorator="['interiorColor', { rules: [{ required: true, message: '请输入内饰颜色' }] }]"
                placeholder="请输入内饰颜色"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="发动机号">
              <a-input
                v-decorator="['engineNumber', { rules: [{ required: false, message: '请输入发动机号' }] }]"
                placeholder="请输入发动机号"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="合格证号">
              <a-input
                v-decorator="['qualifiedNumber', { rules: [{ required: false, message: '请输入合格证号' }] }]"
                placeholder="请输入合格证号"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :sm="12" :xs="24">
            <a-form-item label="动力蓄电池组编号">
              <a-input
                v-decorator="['batteryNumber', { rules: [{ required: carTypeFlag, message: '请输入动力蓄电池组编号' }] }]"
                placeholder="请输入动力蓄电池组编号"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="12" :xs="24">
            <a-form-item label="货物进口证明书编号">
              <a-input
                v-decorator="[
                  'importProveNumber',
                  { rules: [{ required: false, message: '请输入货物进口证明书编号' }] },
                ]"
                placeholder="请输入货物进口证明书编号"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <!--<a-button type="primary" @click="saveDraft">暂存</a-button>-->
    <!--    <edit-order-modal ref="EditOrderModal"> </edit-order-modal>-->
  </j-modal>
</template>

<script>
import { getAction, httpAction } from '@/api/manage'
import moment from 'moment'
import EditOrderModal from './EditOrderModal'

export default {
  name: 'CxmOrderManagerModal',
  components: { EditOrderModal },
  data() {
    return {
      title: '新增订单信息',
      visible: false,
      model: {},
      saleSource: [],
      SaleInfosLike: [],
      pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/,
      components: {
        EditOrderModal
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/cxm/cxmOrderManager/add',
        edit: '/cxm/cxmOrderManager/add',
        saveDraft: 'cxm/cxmCommonBusiness/saveDraft',
        getDraft: 'cxm/cxmCommonBusiness/getDraft',
        getSaleInfosLike: 'cxm/cxmSalesInfo/getSaleInfosLike',
        getSaleInfos: '/cxm/cxmOrderManager/getSaleInfos'
      },
      showDing: false,
      showEnterpriseUscc: false,
      currentTime: '',
      carTypeFlag: false,

    }
  },

  created() {
    this.getCurrentData()
  },
  methods: {

    getCurrentData() {
      if (this.currentTime === '') {
        this.currentTime = moment().format('YYYY-MM-DD HH:mm:ss')
      }
    },

    saleSelect(value) {
      console.log('saleSelect', value)
      for (let i = 0; i < this.SaleInfosLike.length; i++) {
        if (this.SaleInfosLike[i].salesName == value) {
          this.form.setFieldsValue({
            salesPhone: this.SaleInfosLike[i].salesPhone
          })
        }
      }
    },

    documentTypeChange(value) {
      console.log(value)

    },

    validateMobile(rule, value, callback) {
      if (!value || new RegExp(/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/).test(value)) {
        callback()
      } else {
        callback('您的手机号码格式不正确!')
      }

    },

    IdentityVerify(rule, value, callback) {
      console.log(value)
      clearTimeout(checkPending)
      // new RegExp(this.pattern).test(value) ? callback() : callback(new Error('请输入正确的身份证号码'))
      let checkPending
      checkPending = setTimeout(() => {
        if (this.model.documentType !== '1') {
          callback()
        } else if (this.model.documentType === '1' && value !== '' && value !== undefined) {
          if (new RegExp(this.pattern).test(value)) {
            callback()
          } else {
            callback(new Error('身份证格式不正确'))
          }
        } else if (this.model.documentType === '1' && value == undefined) {
          callback(new Error(' '))
        } else if (this.model.documentType === '1' && value == '') {
          callback(new Error(' '))
        }
      }, 10)
    },

    saleChange() {
      setTimeout(() => {
        // console.log(this.form.getFieldValue("salesName"));
        let httpurl = this.url.getSaleInfosLike
        let params = {
          salesName: this.form.getFieldValue('salesName')
        }
        getAction(httpurl, params).then((res) => {
          /* res = {};
          res.success = true; */
          if (res.success) {
            /* res.result = [{
              "salesName": "刘里2",
              "salesPhone": "1321321321323"
            }, {
              "salesName": "刘醒2",
              "salesPhone": "1545454541212"
            }]; */
            this.SaleInfosLike = res.result
            this.saleSource = []
            for (let i = 0; i < res.result.length; i++) {
              this.saleSource.push(res.result[i].salesName)
              if (i > 8) {
                break
              }
            }
          }
        })
      }, 100)
    },
    changeDepositNotes(val) {
      if (val != '' && val != '1') {
        this.showDing = true
      } else {
        this.showDing = false
      }
    },

    changeCarType(val) {
      if (val != '' && val == '2') {
        this.carTypeFlag = true
      } else {
        this.carTypeFlag = false
      }
      // console.log(this.carTypeFlag)
    },

    add() {
      const that = this
      let httpurl = this.url.getDraft
      let params = {
        bType: 'order'
      }
      getAction(httpurl, params).then((res) => {
        console.log(res)
        if (res.success) {
          if (res.result) {
            //有暂存的情况
            that.edit(JSON.parse(res.result), 1)
            // console.log("无结果")
          } else {
            //无暂存的情况
            getAction(that.url.getSaleInfos, params).then((res) => {
              // console.log(res)x
              that.edit(res.result, 2)
              // console.log("结果")
            })
          }
        } else {
          that.edit({})
        }
      })
    },
    edit(record, result) {
      console.log(record)
      this.form.resetFields()
      this.model = Object.assign({}, record)
      console.log(this.model)
      this.visible = true

      if (result == 1) {
        // console.log('有暂存')
        this.$nextTick(() => {
          this.form.setFieldsValue({
            batteryNumber: this.model.batteryNumber,
            businessAddress: this.model.businessAddress,
            carBrand: this.model.carBrand,
            carColor: this.model.carColor,
            carModel: this.model.carModel,
            carType: this.model.carModel,
            carTypeConfiguration: this.model.carTypeConfiguration,
            carVin: this.model.carVin,
            depositAttribute: this.model.depositAttribute,
            depositContent: this.model.depositContent,
            documentNumber: this.model.documentNumber,
            documentType: this.model.documentType,
            engineNumber: this.model.engineNumber,
            // enterpriseId: this.model.enterpriseId,
            enterpriseName: this.model.enterpriseName,
            enterpriseUscc: this.model.enterpriseUscc,
            epositAmount: this.model.epositAmount,
            fuelType: this.model.fuelType,
            importEngineNumber: this.model.importEngineNumber,
            importProveNumber: this.model.importProveNumber,
            interiorColor: this.model.interiorColor,
            isNewCar: this.model.isNewCar,
            // orderDate: this.model.orderDate ? moment(this.model.orderDate) : null,
            orderDate: moment(this.model.orderDate),
            orderNumber: this.model.orderNumber,
            // operationAddr: this.model.operationAddr
            ownerName: this.model.ownerName,
            ownerPhone: this.model.ownerPhone,
            qualifiedNumber: this.model.qualifiedNumber,
            quoteAmount: this.model.quoteAmount,
            // registerDistinct: this.model.registerDistinct,
            region: this.model.region,
            salesName: this.model.salesName,
            salesPhone: this.model.salesPhone
          })
        })
      }

      if (result == 2) {
        // console.log('无暂存')
        this.$nextTick(() => {
          this.form.setFieldsValue({
            batteryNumber: this.model.batteryNumber,
            // businessAddress: this.model.businessAddress,
            businessAddress: this.model.operationAddr,
            carBrand: this.model.carBrand,
            carColor: this.model.carColor,
            carModel: this.model.carModel,
            carType: this.model.carModel,
            carTypeConfiguration: this.model.carTypeConfiguration,
            carVin: this.model.carVin,
            depositAttribute: this.model.depositAttribute,
            depositContent: this.model.depositContent,
            documentNumber: this.model.documentNumber,
            documentType: '1',
            engineNumber: this.model.engineNumber,
            enterpriseUscc: this.model.enterpriseUscc,
            enterpriseName: this.model.enterpriseName,
            // enterpriseUscc: this.model.enterpriseUscc,
            epositAmount: this.model.epositAmount,
            fuelType: this.model.fuelType,
            importEngineNumber: this.model.importEngineNumber,
            importProveNumber: this.model.importProveNumber,
            interiorColor: this.model.interiorColor,
            isNewCar: '是',
            // orderDate: this.model.orderDate ? moment(this.model.orderDate) : null,
            orderDate: moment(this.model.orderDate),
            orderNumber: this.model.orderNumber,
            // operationAddr: this.model.operationAddr
            ownerName: this.model.ownerName,
            ownerPhone: this.model.ownerPhone,
            qualifiedNumber: this.model.qualifiedNumber,
            quoteAmount: this.model.quoteAmount,
            // registerDistinct: this.model.registerDistinct,
            region: this.model.registerDistinct,
            salesName: this.model.salesName,
            salesPhone: this.model.salesPhone
          })
        })

        this.model.documentType = '1'

      }
      // this.$nextTick(() => {
      //   this.form.setFieldsValue({
      //     batteryNumber: this.model.batteryNumber,
      //     // businessAddress: this.model.businessAddress,
      //     businessAddress: this.model.operationAddr,
      //     carBrand: this.model.carBrand,
      //     carColor: this.model.carColor,
      //     carModel: this.model.carModel,
      //     carType: this.model.carModel,
      //     carTypeConfiguration: this.model.carTypeConfiguration,
      //     carVin: this.model.carVin,
      //     depositAttribute: this.model.depositAttribute,
      //     depositContent: this.model.depositContent,
      //     documentNumber: this.model.documentNumber,
      //     documentType: this.model.documentType,
      //     engineNumber: this.model.engineNumber,
      //     enterpriseId: this.model.enterpriseId,
      //     enterpriseName: this.model.enterpriseName,
      //     enterpriseUscc: this.model.enterpriseUscc,
      //     epositAmount: this.model.epositAmount,
      //     fuelType: this.model.fuelType,
      //     importEngineNumber: this.model.importEngineNumber,
      //     importProveNumber: this.model.importProveNumber,
      //     interiorColor: this.model.interiorColor,
      //     isNewCar: this.model.isNewCar,
      //     // orderDate: this.model.orderDate ? moment(this.model.orderDate) : null,
      //     orderDate: moment(this.model.orderDate),
      //     orderNumber: this.model.orderNumber,
      //     // operationAddr: this.model.operationAddr
      //     ownerName: this.model.ownerName,
      //     ownerPhone: this.model.ownerPhone,
      //     qualifiedNumber: this.model.qualifiedNumber,
      //     quoteAmount: this.model.quoteAmount,
      //     // registerDistinct: this.model.registerDistinct,
      //     region: this.model.region,
      //     salesName: this.model.salesName,
      //     salesPhone: this.model.salesPhone,
      //   })
      // })
      if (this.model.enterpriseUscc) {
        this.showEnterpriseUscc = true
      } else {
        this.showEnterpriseUscc = false
      }

    },
    close() {
      this.$emit('close')
      this.form.resetFields()
      this.model = {}
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {

        if (!err) {
          that.confirmLoading = true
          let httpurl = this.url.add
          // if (!this.model.id) {
          //   httpurl += this.url.add
          //
          //   method = 'post'
          // } else {
          //   httpurl += this.url.edit
          //   method = 'put'
          // }
          let formData = Object.assign(this.model, values)
          //时间格式化
          formData.orderDate = formData.orderDate ? formData.orderDate.format('YYYY-MM-DD HH:mm:ss') : null
          formData.id = null

          httpAction(httpurl, formData, 'post')
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
                that.close()
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false

            })
        }
      })
    },
    saveDraft() {
      const that = this
      this.form.validateFields((err, values) => {
        let formData = Object.assign(this.model, values)
        //时间格式化
        formData.orderDate = formData.orderDate ? formData.orderDate.format('YYYY-MM-DD HH:mm:ss') : null
        formData.id = null

        let httpurl = this.url.saveDraft

        console.log(JSON.stringify(formData))
        let Data = {}
        Data.btype = 'order'
        Data.content = JSON.stringify(formData)
        console.log(Data)
        httpAction(httpurl, Data, 'post')
          .then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          })
          .finally(() => {
            that.confirmLoading = false
            that.close()
          })
      })

    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped>

/deep/ .ant-form-item {
  margin-bottom: 15px;
}
</style>